<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <ul>
            <li v-for="user in users">
                {{user.id}} ==> {{user.name}} ==> {{user.gender | genderFilter }}
                <br>
                {{user.gender | gFilter}}
            </li>
        </ul>
    </div>
    <script src="../node_modules/vue/dist/vue.js"></script>
    <script>

        // 全局过滤器
        Vue.filter('gFilter', function (val) {
            if (val == 0) {
                return '男~~~~~'
            } else {
                return '女~~~~~'
            }
        })

        let vm = new Vue({
            el: '#app',
            data: {
                users: [
                    { id: 1, name: 'xx', gender: 0 },
                    { id: 2, name: 'nn', gender: 1 }
                ]
            },
            filters: {
                // "|"使用管道符
                genderFilter(val) {
                    if (val == 0) {
                        return '男'
                    } else {
                        return '女'
                    }
                }
            }
        })
    </script>
</body>

</html>